<?
REQUIRE("../../protect/connect_jeu.php");
REQUIRE ("../fonction.php");
REQUIRE ("../../include/cummonfunction.php");
//Calcul du dernier inscrit.
//--
$query       = "SELECT perso_name FROM sduser_perso order by (perso_date_creation) desc limit 0,1";
$resultat    = mysql_query($query);
$row         = mysql_fetch_array($resultat);
$last_player = $row[0];

//Nombre de ville.
//--
$query     = "SELECT count(*) FROM sdville";
$resultat  = mysql_query($query);
$row       = mysql_fetch_array($resultat);
$nbr_ville = $row[0];

//Nombre d'unite.
//--
$query     = "SELECT count(*) FROM sdunite";
$resultat  = mysql_query($query);
$row       = mysql_fetch_array($resultat);
$nbr_unite = $row[0];

//Nombre de batiment interne.
//--
$query       = "SELECT count(*) FROM sdbatiment WHERE batiment_loc='0'";
$resultat    = mysql_query($query);
$row         = mysql_fetch_array($resultat);
$nbr_bat_int = $row[0];

//Nombre de batiment externe.
//--
$query       = "SELECT count(*) FROM sdbatiment WHERE batiment_loc!='0'";
$resultat    = mysql_query($query);
$row         = mysql_fetch_array($resultat);
$nbr_bat_ext = $row[0];

//Nombre de race dans SD.
//--
$query       = "SELECT count(*) FROM urace";
$resultat    = mysql_query($query);
$row         = mysql_fetch_array($resultat);
$nbr2_race   = $row[0];

//Nombre de CS dans SD.
//--
$query    = "SELECT count(*) FROM uclasse";
$resultat = mysql_query($query);
$row      = mysql_fetch_array($resultat);
$nbr2_cs  = $row[0];

//Nombre de type de batiment dans SD.
//--
$query         = "SELECT count(*) FROM ubatiment";
$resultat      = mysql_query($query);
$row           = mysql_fetch_array($resultat);
$nbr2_batiment = $row[0];

//Nombre de type d'unite dans SD.
//--
$query      = "SELECT count(*) FROM uunite";
$resultat   = mysql_query($query);
$row        = mysql_fetch_array($resultat);
$nbr2_unite = $row[0];

//Nombre de type d'invention dans SD.
//--
$query          = "SELECT count(*) FROM invention";
$resultat       = mysql_query($query);
$row            = mysql_fetch_array($resultat);
$nbr2_invention = $row[0];

//Nombre de type de sort dans SD.
//--
$query          = "SELECT count(*) FROM usort";
$resultat       = mysql_query($query);
$row            = mysql_fetch_array($resultat);
$nbr2_sort      = $row[0];

//Nombre de joueur
//--
$query          = "SELECT count(*) FROM sduser_perso";
$resultat       = mysql_query($query);
$row            = mysql_fetch_array($resultat);
$nbr_perso      = $row[0];



//Premier tableau : statistique du monde
//--------------------------------------
$PAGE.="<table width=\"95%\" border=\"0\" align=\"center\" valign=\"top\"  cellpadding=\"0\" cellspacing=\"2\"><tr><td  width=\"50%\">";
$TMP="<table CLASS=\"td1\"  width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" valign=\"top\" >
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de villes : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr_ville</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de b&acirc;timents internes : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr_bat_int</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de b&acirc;timents externes : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr_bat_ext</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre d'unit&eacute;s : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr_unite</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de joueurs: </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr_perso   </font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">&nbsp; </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;</font></td></tr>

       </table>";
$PAGE.=FIELD_S($TMP,"<b>Statistique du monde</b>");
$PAGE.="</td><td>";
$TMP="<table CLASS=\"td1\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de races : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_race</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de classes sociales : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_cs</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de b&acirc;timents : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_batiment</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre d'unit&eacute;s : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_unite</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre d'inventions : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_invention</font></td></tr>
      <tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">Nombre de sorts : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;$nbr2_sort</font></td></tr>
      </table>";
$PAGE.=FIELD_S($TMP,"<b>Statistique de l'univers</b>");
$PAGE.="</td></tr><tr><td>";

$query    = "SELECT r.race_realname, count(*)
             FROM sduser_perso p, urace r
             where r.race_id = p.perso_race
             GROUP BY race_realname";
$resultat = mysql_query($query);
$TMP="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" CLASS=\"td1\" >";


// boucle sur les resultats
WHILE ($race=mysql_fetch_row($resultat)){
     $TMP.="<tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">$race[0] : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;".number_format($race[1])."</font></td></tr>";
}//Fin de WHILE ($race=mysql_fetch_row($resultat)){
$TMP.="</table>";

$PAGE.=FIELD_S($TMP,"<b>Statistique des races</b>");
$PAGE.="</td><td>";

$TMP="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"  CLASS=\"td1\" >";

//Comptabiliser le nombre de population suivant la race
//------------------------------------------------------------------------------
$query    = "select r.race_realname, sum(v.ville_population)
             from urace r, sdville v
             where v.ville_race = r.race_id
             group by race_realname";
$resultat = mysql_query($query);

// boucle sur les resultats
WHILE ($race=mysql_fetch_row($resultat)){
       $TMP.="<tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">$race[0] : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;".number_format($race[1])."</font></td></tr>";
}
$TMP.="</table>";
$PAGE.=FIELD_S($TMP,"<b>Statistique de la population</b>");


 $PAGE.="</td></tr><tr><td>";
//Compatibliser les classes
//------------------------------------------------------------------------------
$query    = "SELECT classe_name, count(*)
             FROM sduser_perso p, uclasse c
             WHERE c.classe_id = p.perso_classe
             GROUP BY classe_name";
$resultat = mysql_query($query);
$TMP="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" CLASS=\"td1\" >";


// boucle sur les resultats
WHILE ($race=mysql_fetch_row($resultat)){
     $TMP.="<tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">$race[0] : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;".number_format($race[1])."</font></td></tr>";
}//Fin de WHILE ($race=mysql_fetch_row($resultat)){

$TMP.="</table>";

$PAGE.=FIELD_S($TMP,"<b>Statistique des classes</b>");
$PAGE.="</td><td>";



//Comptabiliser le nombre de population suivant la race
//------------------------------------------------------------------------------
$query    = "select c.classe_name, sum(v.ville_population)
             from uclasse c, sdville v,sduser_perso p
             where p.perso_classe = c.classe_id and v.ville_proprio=p.perso_id
             group by c.classe_name";

$resultat = mysql_query($query);
$TMP="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"  CLASS=\"td1\" >";
// boucle sur les resultats
WHILE ($race=mysql_fetch_row($resultat)){
       $TMP.="<tr><td width=\"60%\" align=\"right\"><font CLASS=\"TEXT_BLANC_P\">$race[0] : </font></td><td width=\"40%\"><font CLASS=\"TEXT_GRIS_P\"> &nbsp;".number_format($race[1])."</font></td></tr>";
}
$TMP.="</table>";
$PAGE.=FIELD_S($TMP,"<b>Statistique de la population</b>");




//Fin de la page
$PAGE.="</td>
  </tr>
</table>" ;

  $PAGE=TDF_M($PAGE);
//Modifier les base
$PAGE=addslashes($PAGE);
$query       = "UPDATE sd_stat SET stat_text= '$PAGE' WHERE stat_id=2";
$resultat    = mysql_query($query);


mysql_close();

?>
